/*************************************************************************
	> File Name: tcpserver.h
	> Author: xuwenlong
	> Mail: myxuan475@126.com
	> Created Time: 2018年01月22日 星期一 15时27分51秒
 ************************************************************************/
#ifndef FOUNDATION_DOWNLINK_SERIAL_H
#define FOUNDATION_DOWNLINK_SERIAL_H

#include <utils/lock.h>
#include <vector>
#include <utils/logger.h>
#include "downlink_connect.h"

namespace downlink {
class SerialConnect : public DownlinkConnect {
public:
	SerialConnect(const dbms::DeviceChannel_t &dc);
	virtual ~SerialConnect();

private:
	void ClearWriteBuffer();
	void ClearReadBuffer();

	bool Open();
	void Close();
	int32_t Available(int &timeout);

protected:
	virtual const std::string Name() const override;
	virtual bool ReConnect() override;
	virtual bool Send(const uint8_t cmd[], int32_t len) override;
	virtual int32_t Recv(
		uint8_t cmd[], int32_t max, int32_t timeout = -1) override;
	virtual int32_t Handle();
	virtual void CloseConnect();
	virtual bool IsAvailable() override;

private:
	int32_t comFd_;
	dbms::Serial_t serial_;
};
} // namespace downlink

#endif // FOUNDATION_DOWNLINK_SERIAL_H
